<% var cssExt = [ 
	"/plugins/jquery.bsgrid/builds/merged/bsgrid.all.min.css"
	]; %>
	
<%layout("/template/admin/common/_layout.html", {title: title, cssExt: cssExt}){ %>

<nav class="breadcrumb"><a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
		<a href="javascript:;" onclick="showAdd()" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加</a>
		<a href="javascript:;" onclick="deleteSome()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
		</span>
	</div>
	<div class="mt-20">
	<table id="${table_name!}_Table" class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
			<tr>
        		<th scope="col" colspan="12">${title!}</th>
      		</tr>
			<tr class="text-c">
			<% if(isNotEmpty(col)){ %>
			<% for(x in col){ %>	
				<% if(x.COLUMN_KEY == 'PRI'){  var pri = x.COLUMN_NAME; %>
					<th w_check="true" w_index="${x.COLUMN_NAME!}" width="3%;"></th>
					<th w_index="${x.COLUMN_NAME!}" w_sort="${x.COLUMN_NAME!},desc" width="60">${x.COLUMN_COMMENT!}</th>
				<% }else{ %>
					<th w_index="${x.COLUMN_NAME!}" w_sort="${x.COLUMN_NAME!}" >${x.COLUMN_COMMENT!}</th>
				<% } %>
			<% }} %>
				<th w_render="operate" >操作</th>
			</tr>
		</thead>
	</table>
	</div>
</div>

<script type="text/javascript" src="${ctxPath}/static/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="${ctxPath}/plugins/jquery.bsgrid/builds/js/lang/grid.zh-CN.min.js"></script>
<script type="text/javascript" src="${ctxPath}/plugins/jquery.bsgrid/builds/merged/bsgrid.all.min.js"></script>
<script type="text/javascript">
var gridObj;
/*初始化表格*/
	$.bsgridLanguage.noDataToDisplay = '<font>没有数据</font>'; // can set a html code paragraph	
    gridObj = $.fn.bsgrid.init('${table_name!}_Table', {
        url: '${ctxPath}/manager/table/${table_name!}',
       	//pageSizeSelect: true,
       	autoLoad: false,
        pageSize: ${pageSize!10},
        displayBlankRows: false, // single grid setting
        rowHoverColor: true
    });
    gridObj.page(${pageIndex!1});
	

function operate(record, rowIndex, colIndex, options) {
	var id = gridObj.getRecordIndexValue(record, 'id');
	var ed = '<a href="javascript:;" class="btn btn-secondary-outline radius" onclick="edit(\''+ id + '\');">编辑</a>&nbsp;&nbsp;';
	var dl = '<a href="javascript:;" class="btn btn-danger-outline radius" onclick="del(\''+ id + '\');">删除</a>'
    return ed+dl;
}

function edit(id){
	var index = layer.open({
		type: 2,
		title: '编辑',
		content: '${ctxPath}/manager/edit/${table_name!}-'+id
	});
	layer.full(index);
	console.info(id);
}

function del(id){
	layer.confirm('确认要删除吗？', {icon: 3}, function(index){
		$.ajax({
			 type: "POST",
		      url: "${ctxPath}/manager/delete/${table_name!}-" + id,
		        success: function (data) {
		        	if(data){
		        		layer.alert('删除成功!', {icon: 1}, function(index){
 		        			gridObj.refreshPage();
 		        			layer.close(index);
 		        		});
		        	}else{
		        		layer.alert('删除失败!', {icon: 2}, function(){
 		        			gridObj.refreshPage();
 		        			layer.close(index);
 		        		});
		        	}
		        },
		        error: function (d) {
		        	console.info('请求出错!');
		        }
		    });
	});
	console.info(id);
}

function showAdd(){
	var index = layer.open({
		type: 2,
		title: '添加',
		content: '${ctxPath}/manager/showAdd/${table_name!}'
	});
	layer.full(index);
}


function deleteSome(){
	var ids = gridObj.getCheckedValues('id');
	if(ids.length == 0){
		layer.alert('请选择一个条目!', {icon: 0});
		return;
	}	
	layer.confirm('确认要删除吗？', {icon: 3}, function(index){
		$.ajax({
			 type: "POST",
			 data: {ids : ids.toString()},
		     url: "${ctxPath}/manager/deleteSome/${table_name!}",
		        success: function (data) {
		        	if(data){
		        		layer.alert('删除成功!', {icon: 1}, function(index){
 		        			gridObj.refreshPage();
 		        			layer.close(index);
 		        		});
		        	}else{
		        		layer.alert('删除失败!', {icon: 2}, function(){
 		        			gridObj.refreshPage();
 		        			layer.close(index);
 		        		});
		        	}
		        },
		        error: function (d) {
		        	console.info('请求出错!');
		        }
		    });
	});
}


</script>

<% } %>
